package com.pagepub.expo.manager;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.flex.remoting.RemotingDestination;
import org.springframework.flex.remoting.RemotingInclude;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.pagepub.expo.dao.AppFunctionDao;
import com.pagepub.expo.dao.CorpCommpanyDao;
import com.pagepub.expo.dao.CorpMenuDao;
import com.pagepub.expo.dao.CorpTemplateSourceDao;
import com.pagepub.expo.entity.AppFunction;
import com.pagepub.expo.entity.AppRole;
import com.pagepub.expo.entity.AppUser;
import com.pagepub.expo.entity.CorpCommpany;
import com.pagepub.expo.entity.CorpMenu;
import com.pagepub.expo.entity.CorpTemplateSource;
import com.pagepub.expo.entity.IdName;

@Service
@Transactional
@RemotingDestination(channels = { "my-amf", "my-secure-amf" })
public class CorpCommpanyMng{
	@Autowired
	private CorpCommpanyDao corpCommpanyDao;
	
	@Autowired
	private CorpMenuDao corpMenuDao;

	@RemotingInclude
	@Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
	public List<CorpCommpany> findAll() {
		return corpCommpanyDao.findAll();
	}
	
	@RemotingInclude
	public CorpCommpany findByName(String userName){
		return corpCommpanyDao.findByUserName(userName);
	}
	
	@RemotingInclude
	public CorpCommpany findById(Long id){
		return corpCommpanyDao.findById(id);
	}

	
	@RemotingInclude
	@Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
	public int getCount(Map<String, String> param){
		return corpCommpanyDao.getCount(param);
	}
	
	
	@RemotingInclude
	@Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
	public List<CorpCommpany> findByPage(int currentPage,int pageSize,Map<String, String> param){
		return corpCommpanyDao.findByPage(currentPage, pageSize, param);
	}
	
	
	public List<CorpMenu> getUserCorpMenuByUserId(Long corpTypeId){
		return corpMenuDao.findByCorpTypeId(corpTypeId);
	}


	@RemotingInclude
	public CorpCommpany add(CorpCommpany corpCommpany) {
		corpCommpanyDao.insert(corpCommpany);
		return corpCommpanyDao.findById(new Long(corpCommpany.getId()));
	}

	@RemotingInclude
	public Long remove(Long id) {
		corpCommpanyDao.delete(id);
		return id;
	}

	@RemotingInclude
	public CorpCommpany update(CorpCommpany corpCommpany) {
		corpCommpanyDao.update(corpCommpany);
		return corpCommpanyDao.findById(new Long(corpCommpany.getId()));
	}
	
	@RemotingInclude
	@Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
	public List<IdName> findIdNames(){
		return corpCommpanyDao.findIdNames();
	}
	
	@RemotingInclude
	public void audit(Long id, boolean pass) {
		corpCommpanyDao.audit(id, pass);
	}
}
